package com.ruoyi.business.utils.lock;

import com.ruoyi.common.core.utils.uuid.UUID;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author Wu Yuwei
 * @Description:
 * @date 2023/2/1 17:42
 */
@Component
public class DistributedLockFactory {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    private String uuid;

    // 此无参构造方法在@Component 加载到容器中时都会默认调用  此时生成的uuid时bean实例化时就会生成
    public DistributedLockFactory() {
        this.uuid = UUID.randomUUID().toString();
    }

    public DistributedRedisLock getRedisLock(String lockName){
        return new DistributedRedisLock(stringRedisTemplate,lockName,uuid);
    }
}
